var config = require('../../utils/config');
var util = require('../../utils/util');
var app = getApp();
Page({
  data: {
    classList:[]
  },
  onLoad:function(options) {
    var that = this;
    let userInfo = wx.getStorageSync('user');
    if (userInfo!=null&&userInfo!=undefined&&userInfo!={}&&userInfo!='') {
      that.queryClass(userInfo);
    }else {
      //调用应用实例的方法获取全局数据
      app.getUserInfo(function(userInfo) {
        setTimeout(()=>{
          userInfo = wx.getStorageSync('user');
          that.queryClass(userInfo);
        }, 2000);
      })
    }
  },
  queryClass:function(userInfo) {
    var that = this;    
    var options = {
      url: config.clubApi.getClass,
      data: {
        userId: userInfo.userId
      }
    };
    util.request(options, function(res) {
      if (typeof (res.data.data) !== 'undefined'&&res.data.data!=null) {
        var classs = [];
        for (var i = 0; i < res.data.data.length; i++) {
          classs.push(res.data.data[i]);
        }
        that.setData({
          classList: classs
        })
      }
    });
  },
  addClass:function() {
    wx.navigateTo({
      url: "../addClass/addClass"
    });
  }
})